package com.suyin.ximoon.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.suyin.ximoon.dao.BaseDao;
import com.suyin.ximoon.exception.ServiceException;
import com.suyin.ximoon.plugin.mybatis.Criteria;
import com.suyin.ximoon.service.BaseService;

/***
 * 基础业务实现类，公用的
 * 
 * @author guo
 * */
public abstract class BaseServiceImpl<T> implements BaseService<T> {
	protected Logger logger = LoggerFactory.getLogger(this.getClass());

	private BaseDao<T> baseDao;

	public void setBaseDao(BaseDao<T> baseDao) {
		this.baseDao = baseDao;
	}

	public void insert(T entity) {
		baseDao.insert(entity);
	}

	public void insert(List<T> list) {
		baseDao.insert(list);
	}

	public void update(T entity) throws ServiceException {
		baseDao.update(entity);
	}

	public void update(List<T> list) {
		baseDao.update(list);
	}

	public void deleteById(Integer id) {
		baseDao.deleteById(id);
	}

	@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
	public T queryOne(Integer id) {
		return baseDao.queryOne(id);
	}

	@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
	public List<T> query(Criteria criteria) throws ServiceException {
		return baseDao.query(criteria);
	}

	@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
	public T queryOne(Criteria criteria) throws ServiceException {
		return baseDao.queryOne(criteria);
	}
	@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
	public List<T> queryByPage(T entity) throws ServiceException {
		return baseDao.queryByPage(entity);
	}

	@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
	public Integer count(Criteria criteria) throws ServiceException {
		return baseDao.count(criteria);
	}

	public void delete(Criteria criteria) throws ServiceException {
		baseDao.delete(criteria);
	}

	public void update(Criteria criteria) throws ServiceException {
		baseDao.update(criteria);
	}

	public void updateBatch(List<Criteria> criterias) throws ServiceException {
		baseDao.updateBatch(criterias);

	}

	public void insert(Criteria criteria) throws ServiceException {
		baseDao.insert(criteria);
	}

	public void insertBatch(List<Criteria> criterias) throws ServiceException {
		baseDao.insertBatch(criterias);
	}
}
